package com.yuanss.backenddemo.controller;

import com.yuanss.backenddemo.common.R;
import com.yuanss.backenddemo.constant.MenuConstant;
import com.yuanss.backenddemo.service.SysMenuService;
import com.yuanss.backenddemo.utils.ShiroUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author yuanss
 * @version 1.0
 * @description 菜单api
 * @date 2024/6/15 21:42:09
 */
@RestController
@RequestMapping("/menus")
public class MenuController {

    @Resource
    private SysMenuService sysMenuService;

    @GetMapping
    public R getMenus(@RequestParam String type){
        R res;
        if(MenuConstant.QueryMenuType.ALL.equals(type)){
            res = sysMenuService.treeMenu();
        }else if(MenuConstant.QueryMenuType.USER.equals(type)){
            res =  sysMenuService.treeMenuByUserId(ShiroUtils.getUserId());
        }else {
            res = R.error("参数错误");
        }
        return res;
    }

}
